package ch.fhnw.kosmonauten.client.gui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import ch.fhnw.kosmonauten.model.User;
/**
 * Diese Klasse stellt die Fehlermeldung dar.
 * 
 * @author Fabian Siegrist
 * @author Oliver Freiermuth
 * @author Mikhail Onoufrienko
 * @author Risto Milani
 * @version $Revision: 221 $
 *          File name: $HeadURL: http://iching-kosmonauten.googlecode.com/svn/I-Ching/src/ch/fhnw/kosmonauten/client/gui/ErrorDialog.java $
 *          Last modified:$Date: 2013-05-27 19:18:54 +0000 (Mon, 27 May 2013) $
 *          Last modified by: $Author: molotok.mihon@gmail.com $
 */

// class definition
public class ErrorDialog {

	// attributes
	private Error[] list;
	private User user;
	
	// methods
	private void init() {
		list = new Error[15];
		list[0] = new Error(0, "Warnung", user.displayValue("mw116"));
		list[1] = new Error(1, "Warnung", user.displayValue("mw117") + "\n");
		list[2] = new Error(2, "Information", user.displayValue("mw118") + "\n");
		list[3] = new Error(3, "Information", user.displayValue("mw137") + "\n");
		list[4] = new Error(4, "Error", user.displayValue("mw119") + "\n");
		list[5] = new Error(5, "Error", user.displayValue("mw120") + "\n");
		list[6] = new Error(6, "Information", user.displayValue("mw121") + "\n");
		list[7] = new Error(7, "Information", user.displayValue("mw122") + "\n");
		list[8] = new Error(8, "Information", user.displayValue("mw128") + "\n");
		list[9] = new Error(9, "Information", user.displayValue("mw129") + "\n");
		list[10] = new Error(10, "Information", user.displayValue("mw130") + "\n");
		list[11] = new Error(11, "Information", user.displayValue("mw131") + "\n");
		list[12] = new Error(12, "Information", user.displayValue("mw132") + "\n");
		list[13] = new Error(13, "Information", user.displayValue("mw133") + "\n");
		list[14] = new Error(14, "Information", user.displayValue("mw135") + "\n");
	}

	/**
	 * @param key
	 * @return
	 */
	private Error getError(int key) {
		for (Error err : list) {
			if (err.getKey() == key)
				return err;
		}
		return null;
	}

	/**
	 * @param errorcode
	 */
	public ErrorDialog(int errorcode, int type, User user) {
		this.user = user;
		this.init();
		this.showErrorMessage(this.getError(errorcode), type);
	}
	
	/**
	 * @param errorcode
	 */
	public ErrorDialog(String message) {
		this.showErrorMessage(message, JOptionPane.INFORMATION_MESSAGE);
	}

	/**
	 * @param error
	 */
	private void showErrorMessage(Error error, int type ) {
		if (error != null)
			JOptionPane.showMessageDialog(new JFrame(), error.getMessage(),
					error.getTitle(), type);
		else
			JOptionPane.showMessageDialog(new JFrame(),
					"Ein Fehler ist aufgetretten.", "Warnung",
					JOptionPane.ERROR_MESSAGE);
	}
	
	/**
	 * @param error
	 */
	private void showErrorMessage(String message, int type ) {
			JOptionPane.showMessageDialog(new JFrame(), message,"Information", type);
	}
	
	}